package com.tencent.trtc.apiexample.ui.notifications;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;

import com.alibaba.fastjson.JSON;
import com.tencent.trtc.apiexample.AlterActivity;
import com.tencent.trtc.apiexample.AlterPwdActivity;
import com.tencent.trtc.apiexample.LoginActivity;
import com.tencent.trtc.apiexample.R;
import com.tencent.trtc.apiexample.WebServiceGet;
import com.alibaba.fastjson.*;

import static com.tencent.trtc.apiexample.LoginActivity.PATH;
import static com.tencent.trtc.apiexample.LoginActivity.USERNAME;
import static com.tencent.trtc.apiexample.LoginActivity.json;

public class NotificationsFragment extends Fragment {
    private NotificationsViewModel notificationsViewModel;


    public View onCreateView(@NonNull LayoutInflater inflater,
                             ViewGroup container, Bundle savedInstanceState) {
        notificationsViewModel =
                new ViewModelProvider(this).get(NotificationsViewModel.class);
        View root = inflater.inflate(R.layout.fragment_notifications, container, false);
        return root;
    }

    @Override
    public void onActivityCreated(@Nullable @org.jetbrains.annotations.Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        getView().findViewById(R.id.btn_alter).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(getActivity(), AlterActivity.class);
                startActivity(intent);
            }
        });

        getView().findViewById(R.id.btn_exit).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(getActivity(), LoginActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK|Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(intent);
            }
        });

        getView().findViewById(R.id.btn_alter_password).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(getActivity(), AlterPwdActivity.class);
                startActivity(intent);
            }
        });

        TextView text1 = getView().findViewById(R.id.tv_username);
        text1.setText(USERNAME);

        TextView text2 = getView().findViewById(R.id.tv_usertel);
        text2.setText(json.getString("telephone"));

        TextView text3 = getView().findViewById(R.id.tv_useremail);
        text3.setText(json.getString("email"));

    }

}